﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ncp.Business;
using ncp.Business.Common;

namespace ncp.Web.member
{
    public partial class shop_about : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var userInfo = WebMasterCookie.GetCookie();
            if (userInfo == null)
            {
                Response.Redirect("/login.aspx");
            }
            AjaxPro.Utility.RegisterTypeForAjax(typeof(shop_about));
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string GetAbout()
        {
            Dictionary<string, object> jsonResult = new Dictionary<string, object>();
            var userInfo = WebMasterCookie.GetCookie();
            if (userInfo != null)
            {
                var table = ClientInfoBll.GetClientInfoTable("Client_Id=" + userInfo.Id, "Client_Id asc", CommonConst.DB_Name);
                if (table.Rows.Count > 0)
                {
                    jsonResult.Add("msg", table.Rows[0]["User_Remark"]);
                    jsonResult.Add("isreload", true);
                }
                else
                {
                    jsonResult.Add("isreload", false);
                    jsonResult.Add("msg", "非法用户，请退出重新登录！");
                }
            }
            else
            {
                jsonResult.Add("isreload", false);
                jsonResult.Add("msg", "登录超时，请退出重新登录！");
            }
            return "[" + JsonHelper.ObjectToJSON(jsonResult) + "]";
        }

        //保存用户信息
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string SaveAboutUs(string content)
        {
            Dictionary<string, object> jsonResult = new Dictionary<string, object>();
            try
            {
                var userInfo = WebMasterCookie.GetCookie();
                if (userInfo != null)
                {
                    ClientInfoBll.SaveAboutUs(content, userInfo.Id, CommonConst.DB_Name);
                    Dictionary<string, object> dicHandleLog = new Dictionary<string, object>();
                    dicHandleLog.Add("user_id", userInfo.Id);
                    dicHandleLog.Add("computername", userInfo.Computername);
                    dicHandleLog.Add("computerip", userInfo.Computerip);
                    dicHandleLog.Add("handle_note", "修改关于我们");
                    dicHandleLog.Add("obj_guid", "Client_Id=" + userInfo.Id);
                    LogHandleBll.AddHandleLog(dicHandleLog, CommonConst.DB_Name);
                    jsonResult.Add("isreload", true);
                    jsonResult.Add("msg", "修改成功！");
                }
                else
                {
                    jsonResult.Add("isreload", false);
                    jsonResult.Add("msg", "登录超时，请退出重新登录！");
                }
            }
            catch (Exception ex)
            {
                jsonResult.Add("isreload", false);
                jsonResult.Add("msg", ex.Message);
            }
            
            return "[" + JsonHelper.ObjectToJSON(jsonResult) + "]";
        }
    }
}
